<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
*{
    margin: 0;
    padding: 0;
}
/* html{
    font-size: 20px;/*  根部字体大小
} */
.wrap{
     width: 5rem;/* 相对于根部(html)*/
height: 5rem;
border: 1px solid #000;
text-align: center;
line-height: 100px;
font-size: 20px;
margin: 0 auto;
margin-top: 50px;
}
 /* @media screen and (min-width:400px){/* 大于等于400
    .wrap{
        width: 200px;
    }
}
@media screen and (max-width:400px){/* 小于等于400
    .wrap{
        width: 160px;
    }
} */

/* @media screen and (min-width:400px){
    html{
        font-size: 24px;
    }
} */
    </style>
    <script>
        (function(window){
        let width =  document.documentElement.clientWidth //获取手机宽度
        let fontS = width / 10;
        document.documentElement.style.fontSize = fontS + 'px'
        console.log(width)
        })(window)
    </script>
</head>
<body>
    <div class="wrap">hello world</div>
</body>
</html>